package com.atguigu.spzx.manager.controller;

import com.atguigu.spzx.manager.service.CategoryBrandService;
import com.atguigu.spzx.model.dto.product.CategoryBrandDto;
import com.atguigu.spzx.model.entity.product.Brand;
import com.atguigu.spzx.model.entity.product.CategoryBrand;
import com.atguigu.spzx.model.vo.common.Result;
import com.atguigu.spzx.model.vo.common.ResultCodeEnum;
import com.github.pagehelper.PageInfo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @ClassName: CategoryBrandController
 * @Package: com.atguigu.spzx.manager.controller
 * @Description 分类品牌列表分页
 * @Author 孤妤
 * @Date: 2023/12/8 8:43
 */
@Tag(name = "分类品牌")
@RestController
@RequestMapping("/admin/product/categoryBrand")
public class CategoryBrandController {
    @Autowired
    private CategoryBrandService categoryBrandService;
    @GetMapping("/{pageNum}/{pageSize}")
    @Operation(summary = "分类品牌列表分页")
    public Result<PageInfo<CategoryBrand>> findCategoryBrandPage(@PathVariable Integer pageNum,
                                                                 @PathVariable Integer pageSize,
                                                                 CategoryBrandDto categoryBrandDto){
        PageInfo<CategoryBrand> pageInfo = categoryBrandService.findCategoryBrandPage(pageNum,pageSize,categoryBrandDto);
        return Result.build(pageInfo, ResultCodeEnum.SUCCESS);
    }
    @PostMapping("/save")
    @Operation(summary = "添加分类品牌")
    public Result addCategoryBrand(@RequestBody CategoryBrandDto categoryBrandDto){
        categoryBrandService.addCategoryBrand(categoryBrandDto);
        return Result.build(null,ResultCodeEnum.SUCCESS).setMsg("添加成功");
    }
    @PutMapping("/updateById")
    @Operation(summary = "修改分类品牌")
    public Result changeCategoryBrandById(@RequestBody CategoryBrand categoryBrand){
        categoryBrandService.changeCategoryBrandById(categoryBrand);
        return Result.build(null,ResultCodeEnum.SUCCESS).setMsg("修改成功");
    }
    @DeleteMapping("/deleteById/{id}")
    @Operation(summary = "删除分类品牌")
    public Result removeCategoryBrandById(@PathVariable Long id){
        categoryBrandService.removeCategoryBrandById(id);
        return Result.build(null,ResultCodeEnum.SUCCESS).setMsg("删除成功");
    }
    @GetMapping("/FindBrandByCategoryId/{id}")
    @Operation(summary = "根据分类id查询指定品牌")
    public Result<List<Brand>> FindBrandByCategoryId(@PathVariable Long id){
        List<Brand> brandList = categoryBrandService.FindBrandByCategoryId(id);
        return Result.build(brandList,ResultCodeEnum.SUCCESS);
    }
}
